/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jpa.session;

import javax.ejb.Stateless;
import javax.faces.model.DataModel;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import jpa.entities.Material;

/**
 *
 * @author jordan
 */
@Stateless
public class MaterialFacade extends AbstractFacade<Material> {
    @PersistenceContext(unitName = "ColetaSeletivaAuto2PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public MaterialFacade() {
        super(Material.class);
    }
    public DataModel buscarMaterial(String descricao)
    {
        DataModel items = null;
        try 
        {
            items = (DataModel) em.createNamedQuery("Material.findByDescricao")
            .setParameter("descricao", descricao)
            .getSingleResult();
            /*
            items = (DataModel) em.createNamedQuery("Material.findById")
            .setParameter("id", '1')
            .getSingleResult();
            */
            
        } catch (Exception e) 
        {
            return null;
        }
        return items;
    }
    
}
